package com.zhisheng.sql.blink.stream.example.test;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

// 单例模式管理动态参数
public class LocalParamManager {
    private static volatile int currentId = 10; // 初始值
    private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);

    // 获取当前参数值
    public static int getCurrentId() {
        return currentId;
    }

    // 动态更新参数值（例如每小时更新）
    public static void scheduleUpdate(int initialDelay, int period, TimeUnit unit) {
        scheduler.scheduleAtFixedRate(() -> {
            // 模拟参数变化逻辑（例如每小时后 currentId += 10）
            currentId += 10;
            System.out.println("Updated currentId to: " + currentId);
        }, initialDelay, period, unit);
    }

    // 关闭定时任务
    public static void shutdown() {
        scheduler.shutdown();
    }


    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello world");
            }
        },1000,1000);

    }
}